<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {html_options} function plugin
 *
 * Type:     function<br />
 * Name:     html_options<br />
 * Input:<br />
 *           - name       (optional) - string default "select"
 *           - values     (required if no options supplied) - array
 *           - options    (required if no values supplied) - associative array
 *           - selected   (optional) - string default not set
 *           - output     (required if not options supplied) - array
 * Purpose:  Prints the list of <option> tags generated from
 *           the passed parameters
 * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
 *      (Smarty online manual)
 * @param array
 * @param Smarty
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_mm_alpha($params, &$smarty)
{

	$key		= 'c';

	if(isset($params['key']))
	{

		$key	= $params['key'];

	}

	$base_url	= preg_replace("/(\?|&)$key=([^&]*)/", '', $_SERVER['REQUEST_URI']);

	if(isset($params['base']))
	{

		$base_url	= $params['base'];

	}

	$base_url		= str_replace('&', '&amp;', $base_url);

	$selected	= @$_REQUEST[$key];

	if(isset($params['sel']))
	{

		$selected	= $params['sel'];

	}

	$alpha	= array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'other');
	$html	= null;

	for($i = 0; $i < count($alpha); $i++)
	{

		if($selected == $alpha[$i])
		{

			$html .= '<strong>'. $alpha[$i] .'</strong>';

		}
		else
		{

			$html .= '<a href="'. $base_url .'&amp;'. $key .'='. $alpha[$i] .'">'. $alpha[$i] .'</a>';

		}

		if($i != count($alpha) - 1)
		{

			$html .= ' | ';

		}

	}

	return $html;

}

?>
